<template>
  <div class="mod-config sys-frequency">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="参数名" prop="paramKey">
      <el-input v-model="dataForm.paramKey" placeholder="参数名"></el-input>
    </el-form-item>
    <el-form-item label="参数值" prop="paramValue">
      <el-input v-model="dataForm.paramValue" placeholder="参数值"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item style="text-align: right;">
      <el-button type="success" @click="dataFormSubmit">确定</el-button>
    </el-form-item>
    </el-form>
    <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update> -->
  </div>
</template>

<script>
  import AddOrUpdate from './config-add'
  export default {
    data () {
      return {
        dataForm: {
          id: 0,
          paramKey: '',
          paramValue: '',
          remark: ''
        },
        dataRule: {
          paramKey: [
            { required: true, message: '参数名不能为空', trigger: 'blur' }
          ],
          paramValue: [
            { required: true, message: '参数值不能为空', trigger: 'blur' }
          ]
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
    },
    activated () {
      this.init()
    },
    methods: {
       init () {
        this.visible = true
        this.$http({
          url: this.$http.adornUrl(`/sys/config/info/4`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataForm.paramKey = data.config.paramKey
            this.dataForm.paramValue = data.config.paramValue
            this.dataForm.remark = data.config.remark
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$http({
          url: this.$http.adornUrl(`/sys/config/update`),
          method: 'post',
          data: this.$http.adornData({
            'id': 4,
            'paramKey': this.dataForm.paramKey,
            'paramValue': this.dataForm.paramValue,
            'remark': this.dataForm.remark
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      }
    }
  }
</script>
